package edu.java.homework.hw04.classes;

/**
 * This class implements a segment in Euclid's plain. This class use as instance
 * variables 2 objects with type Point2D class
 * 
 * @author Tsvetan Vasilev
 * 
 */
public class Segment2D {

    // --- Instance Variables --------------------------------------------------
    private Point2D startPoint = null;
    private Point2D endPoint = null;

    // --- Constructors --------------------------------------------------------
    public Segment2D() {
	startPoint = new Point2D();
	endPoint = new Point2D();
    }

    public Segment2D(Point2D startPoint, Point2D endPoint) {
	// Podvoden kamak. Tozi konstruktor moje da go napravq po 2 nachina.

	// Po 1qt nachin shte sazdam 2 napalno novi obekta ot tip Point2D.
	// Po tozi nachin chlen-promenlivite na segment2D nqma da sochat kam
	// obektite, koito sa podadeni kato formalni parametri

	// this.startPoint = new Point2D(startPoint);
	// this.endPoint = new Point2D(endPoint);

	// Po 2qt nachin poletata na Segment2D sochat kam obektite podadeni kato
	// formalni parametri

	this.startPoint = startPoint;
	this.endPoint = endPoint;
    }

    public Segment2D(double coordX1, double coordY1, double coordX2,
	    double coordY2) {
	this(new Point2D(coordX1, coordY1), new Point2D(coordX2, coordY2));
    }

    // --- Getters and Setters -------------------------------------------------
    public Point2D getStartPoint() {
	return startPoint;
    }

    public void setStartPoint(Point2D startPoint) {
	this.startPoint = new Point2D(startPoint);
    }

    public Point2D getEndPoint() {
	return endPoint;
    }

    public void setEndPoint(Point2D endPoint) {
	this.endPoint = new Point2D(endPoint);
    }

    // --- Methods -------------------------------------------------------------
    @Override
    public String toString() {
	String result = "[ " + getStartPoint().toString() + ", "
		+ getEndPoint().toString() + " ]";
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (obj == null) {
	    return false;
	}

	if (this == obj) {
	    return true;
	}

	if (!(obj instanceof Segment2D)) {
	    return false;
	}

	Segment2D segment = (Segment2D) obj;
	boolean isEqualStartPoint = getStartPoint().equals(
		segment.getStartPoint());
	boolean isEqualEndPoint = getEndPoint().equals(segment.getEndPoint());
	// if(
	return (isEqualStartPoint) && (isEqualEndPoint);
	// ){
	// return true;
	// }else{
	// return false;
	// }
    }
}
